package com.example.foobar.dto;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.metadata.BaseRowModel;
import com.example.foobar.vo.RetentionRateVO;
import io.lettuce.core.dynamic.support.ReflectionUtils;
import lombok.Data;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

@Data
public class RateDataForExcel extends BaseRowModel {
    @ExcelProperty("日期")
    private String date;

    @ExcelProperty("备注")
    private String remark;

    @ExcelProperty("新增用户")
    private int newCommerCount;

    @ExcelProperty("当天活跃度")
    private String rate1;

    @ExcelProperty("第2天")
    private String rate2;

    @ExcelProperty("第3天")
    private String rate3;

    @ExcelProperty("第4天")
    private String rate4;

    @ExcelProperty("第5天")
    private String rate5;

    @ExcelProperty("第6天")
    private String rate6;

    @ExcelProperty("第7天")
    private String rate7;

    @ExcelProperty("第8天")
    private String rate8;

    @ExcelProperty("第9天")
    private String rate9;

    @ExcelProperty("第10天")
    private String rate10;

    @ExcelProperty("第11天")
    private String rate11;

    @ExcelProperty("第12天")
    private String rate12;

    @ExcelProperty("第13天")
    private String rate13;

    @ExcelProperty("第14天")
    private String rate14;

    @ExcelProperty("第15天")
    private String rate15;

    @ExcelProperty("第16天")
    private String rate16;

    @ExcelProperty("第17天")
    private String rate17;

    @ExcelProperty("第18天")
    private String rate18;

    @ExcelProperty("第19天")
    private String rate19;

    @ExcelProperty("第20天")
    private String rate20;

    @ExcelProperty("第21天")
    private String rate21;

    @ExcelProperty("第22天")
    private String rate22;

    @ExcelProperty("第23天")
    private String rate23;

    @ExcelProperty("第24天")
    private String rate24;

    @ExcelProperty("第25天")
    private String rate25;

    @ExcelProperty("第26天")
    private String rate26;

    @ExcelProperty("第27天")
    private String rate27;

    @ExcelProperty("第28天")
    private String rate28;

    @ExcelProperty("第29天")
    private String rate29;

    @ExcelProperty("第30天")
    private String rate30;

    public RateDataForExcel(RetentionRateVO retentionRateVO){
        this.date = retentionRateVO.getDate();
        this.remark = retentionRateVO.getRemark();
        this.newCommerCount = retentionRateVO.getNewCommerCount();
        List<RetentionRateDTO> rateDTOS = retentionRateVO.getRateDTOS();
        for(int i = 0; i< rateDTOS.size() ;i++){
            Method method = ReflectionUtils.findMethod(RateDataForExcel.class, "setRate" + "" + (i + 1) + "", String.class);
            ReflectionUtils.invokeMethod(method, this, rateDTOS.get(i).getRetentionRate());
        }
    }

    public static List<RateDataForExcel> buildListRateDataForExcel(List<RetentionRateVO> retentionRateVOS){
        List<RateDataForExcel> result = new ArrayList<>();
        retentionRateVOS.forEach(vo -> {
            result.add(new RateDataForExcel(vo));
        });
        return result;
    }
}
